layui.use(['layer', 'form', 'ax', 'table', 'admin', 'laydate'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    var SysAuditlModule = {
        tableId: "SysAuditlModuleTable"
    };

    var tableResult = table.render({
        elem: '#' + SysAuditlModule.tableId,
        url: Feng.ctxPath + '/sysAuditl/page',
        page: true,
        title:"用户审计",
        size: 'sm',
        height: "full-98",
        toolbar: '#toolbarDemo',
        cellMinWidth: 100,
        even: true,
        loading: true,
        request: { pageName: 'current', limitName: 'size'},
        // response: { statusName: 'code' ,statusCode: 200 ,msgName: 'message' ,countName: 'total' ,dataName: 'records' },
        parseData: function(res){
            return {
                "code": 0, //解析接口状态
                "msg": res.message, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": res.data.records //解析数据列表
            };
        },
        cols: [[
            {type: 'checkbox'},
            {field: 'logId', hide: true, title: '主键'},
            {field: 'logTitle', title: '操作描述' ,align: 'center',edit: 'text'},
            {field: 'logRemote', title: '远程地址' ,align: 'center',edit: 'text'},
            {field: 'logMac', title: '标识' ,align: 'center',edit: 'text'},
            {field: 'logAgent', title: '访问类型' ,align: 'center',edit: 'text'},
            {field: 'logUri', title: '请求路径' ,align: 'center',edit: 'text'},
            {field: 'logMethod', title: '请求方式' ,align: 'center',edit: 'text'},
            {field: 'logParams', title: '请求参数' ,align: 'center',edit: 'text'},
            {field: 'logException', title: '异常信息' ,align: 'center',edit: 'text'},
            {field: 'userAccount', title: '操作账号' ,align: 'center',edit: 'text'},
            {field: 'userName', title: '操作人' ,align: 'center',edit: 'text'},
            {field: 'createTime', title: '操作时间' ,align: 'center'},
        ]]
    });
    table.on('tool(' + SysAuditlModule.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'btnEdit') {
            SysAuditlModule.openEditDlg(data);
        } else if (layEvent === 'btnDelete') {
            SysAuditlModule.onDeleteItem(data);
        }
    });

    //////////////////////查询/////////////////////
    $('#btnSearch').click(function () {
        SysAuditlModule.search();
    });
    SysAuditlModule.search = function () {
        var queryData = {};
        queryData['logTitle'] = $("#logTitle").val();
        table.reload(SysAuditlModule.tableId, {where: queryData});
    };


    //////////////////////重置/////////////////////
    $('#btnReset').click(function () {
        $("#logTitle").val("");
        SysAuditlModule.search();
    });

    //监听单元格编辑
    table.on('edit(SysAuditlModuleTable)', function(obj){
        var value = obj.value; //得到修改后的值
        var data = obj.data; //得到所在行所有键值
        var field = obj.field; //得到字段
        // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);

        //console.log("[obj]"+JSON.stringify(obj.data));
        //obj]{"createTime":"2020-07-29 18:42:17","logAgent":"ApiPOST Runtime +https://www.apipost.cn","logException":"","logId":1,"logMac":"00-1E-64-F6-BA-0D","logMethod":"POST","logParams":"id=1","logRemote":"192.168.1.12","logTitle":"修改密码11","logUri":"/oauth/token","tenantId":1,"userAccount":"zhangsan","userName":"张三"}

        var ajax = new $ax(Feng.ctxPath + "/sysAuditl/update", function (data) {
            Feng.success("修改成功！");
        }, function (data) {
            Feng.error("修改失败！" + data.responseJSON.message)
        });
        //[data.field]{"deptId":"27","simpleName":"战略部1","pid":"24","pName":"良品信息技术有限公司","sort":"4"}
        //alert("[data.field]"+JSON.stringify(data.field));
        ajax.set(data);
        ajax.start();
    });



});
